Skip to content

gh-157676: Fix KeyError in tkinter.simpledialog when a foreign window holds the grab - #157677

Merged
serhiy-storchaka merged 4 commits into
python:mainfrom
serhiy-storchaka:gh-157676-simpledialog-grab
Sep 29, 2026
Merged

serhiy-storchaka merged 4 commits into
python:mainfrom
serhiy-storchaka:gh-157676-simpledialog-grab

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

_temp_grab_focus() used grab_current() and focus_get(), which raise KeyError for windows which were not created by tkinter, such as a native message box. Use Tcl window names instead. Regression from #151848, not released.

🤖 Generated with Claude Code

…window holds the grab

_temp_grab_focus() used grab_current() and focus_get(), which raise
KeyError for windows which were not created by tkinter, such as a native
message box.  Use Tcl window names instead.
The dialog can destroy a temporary default root, and then even "winfo"
fails with "application has been destroyed".
On the Windows CI runners "focus -force" has no effect, because
SetForegroundWindow() is refused for a background process.
The application can lose the focus when the dialog is destroyed, and
"focus" without -force does not take it back.
@serhiy-storchaka
serhiy-storchaka merged commit 3736342 into python:main Sep 29, 2026
49 checks passed
@serhiy-storchaka
serhiy-storchaka deleted the gh-157676-simpledialog-grab branch September 29, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant